#ifndef EXECUTE_PLAN_H
#define EXECUTE_PLAN_H

#include "inc.h"
#include "parser.h"

#define MAX_PLAN_NODES 2
#define MAX_VALUE_SIZE 80
#define MAX_VALUE_NUM 10
#define MAX_CONDITION_NUM 10
#define TEST_PLAN

typedef enum {
    PLAN_INSERT, PLAN_DELETE, PLAN_UPDATE,
    PLAN_SCAN, PLAN_PROJECT, PLAN_FILTER,
    PLAN_JOIN, PLAN_UNKNOWN
} PlanNodeType;

typedef struct valueList {
    char *value[MAX_VALUE_NUM];
    int count;
} valueList;

typedef struct exprList {
    char seperator[MAX_CONDITION_NUM];  /* seperator of conditions --> (, => and) (: => or)  (\0 => end) */
    char *column[MAX_CONDITION_NUM];
    char *operator[MAX_CONDITION_NUM];
    char *value[MAX_CONDITION_NUM];
    int count;  /* the count of expressions */
} exprList;

typedef struct PlanNode {
    PlanNodeType type; 
    struct PlanNode *children[MAX_PLAN_NODES];
    union {
        valueList *value_list;
        exprList *expr_list;
    };
    int child_count;
} PlanNode;

PlanNode *buildPlanTree(ASTNode *root);
void printPlan(PlanNode *root);
void destroyPlanTree(PlanNode *root);

#ifdef TEST_PLAN
PlanNode *selectToPlan(ASTNode *stmt);
#endif  /* TEST_PLAN */

#endif  /* EXECUTE_PLAN_H */